package com.h117121.fashionshop.core.tool;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.h117121.fashionshop.core.dom.Account;
import com.h117121.fashionshop.core.dom.Cart;
import com.h117121.fashionshop.core.dom.Invoice;
import com.h117121.fashionshop.core.dom.Invoice.InvoiceState;
import com.h117121.fashionshop.core.dom.Invoice.PaymentMethod;
import com.h117121.fashionshop.core.dom.ProductInCart;
import com.h117121.fashionshop.core.dom.ProductInInvoice;

public class Utils {
	private Utils() {
	}

	public static boolean isNullOrEmpty(String string) {
		if (string == null || string.isEmpty())
			return true;
		return false;
	}

	public static Invoice convertToInvoice(Cart cart, Account acc, Date dateCreated,
			Date datePaid, PaymentMethod paymentMethod, InvoiceState state) {
		Invoice invoice = new Invoice();
		invoice.setAccount(acc);
		invoice.setDateCreated(dateCreated);
		invoice.setDatePaid(datePaid);
		invoice.setPaymentMethod(paymentMethod);
		invoice.setState(state);
		List<ProductInInvoice> products = new ArrayList<ProductInInvoice>();
		for (ProductInCart product : cart.getItems()) {
			ProductInInvoice pii = new ProductInInvoice();
			pii.setProductId(product.getProduct().getId());
			pii.setName(product.getProduct().getName());
			pii.setPrice(product.getProduct().getPrice());
			pii.setQuantity(product.getQuantity());
			products.add(pii);
		}
		invoice.setProducts(products);
		return invoice;
	}
}
